var textdata = {};

(function($){

    $.fn.extend({
        imghover : function(options, arg) {
            if (typeof(options) == "object") {
                options = $.extend({}, $.imghover.defaults, options);
            }
            this.each(function() {
                for (var fld in options) {
                    jQuery(this).attr("plugin_ih_" + fld, options[fld]);
                }
                new $.imghover(this, options, arg);
            });
            return;
        }
    });

    $.imghover = function(item, options, arg) {
        var myName = item.name;
        var timeout = null;
        jQuery(item).val(options.defaulttext);
        var pos = jQuery(item).offset();
        if (typeof(options) == "string") {
            var methodName = options;
            options = {};
            for (var fld in $.textsearch.defaults) {
                options[fld] = jQuery(item).attr("plugin_ih_" + fld);
            }
            // methods
        } else {
            jQuery(item)
                .mouseover(function() {
                    var pos = jQuery(this).offset();
                    var box = jQuery("<div>")
                        .attr("id", this.name + "_description")
                        .addClass("img_description")
                        .css({
                            display : "none",
                            position:"absolute",
                            top : pos.top-2,
                            left : pos.left - 2,
                            width : this.width + 150,
                            height : this.height,
                        })
                        .append(jQuery("<img>")
                            .attr("src", this.src)
                            .attr("width", this.width)
                            .attr("height", this.height)
                            .css({
                                "float" : "left"
                            })
                        )
                        .append(jQuery("<div>")
                        )
                        .mouseout(function() {
                            jQuery(this)
                                .empty()
                                .remove()
                            ;
                        })
                        .appendTo(jQuery("body"))
                        .show("fade", {}, 200)
                    ;
                    if (timeout) {
                        clearTimeout(timeout);
                        timeout = null;
                    }
                    timeout = setTimeout(function() {
                        callService(options.page, options.gettextservice, {
                            company_id : jQuery(item).attr("company_id")
                        }, {
                            success : function(result) {
                                box.find("div").html(result.html);
                            }
                        });
                    }, 800);
                })
            ;
        }

        $.imghover.defaults = {
            gettextservice : "",
            page : ""
        }
    }
})(jQuery);
